home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11796 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  5.1 KB

  1. Path: inforamp.net!ts14-03
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Coding Standards
  5. Date: Sat, 16 Mar 96 08:03:03 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4idskb$pc1@sam.inforamp.net>
  8. References: <4hj8ek$elu@sam.inforamp.net> <4hktar$5o2@galaxy.ucr.edu> <4hmqol$97j@abacus.abasoft.co.uk> <4hsg8r$pmm@sam.inforamp.net> <4i9o6j$p4l@daisy.pgh.wec.com>
  9. NNTP-Posting-Host: ts14-03.tor.inforamp.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4i9o6j$p4l@daisy.pgh.wec.com>,
  13.    zcewj@cnfd.pgh.wec.com (Elliot W. Jackson) wrote:
  14. >Without passing judgement at all on your knowledge or experience level, I
  15. >suggest that it might be worth your while to re-examine your position.  The
  16. >wise man will recognize that when he begins to think "The whole world is
  17. >wrong but me!", that usually (but not always) means that it is time for a
  18. >little re-evaluation.
  19.  
  20. You see, I've worked on dozens of projects and most of them had coding 
  21. standards.  And most of those coding standards were reasonable.  This coding 
  22. standard was a joke.  You see, the company even agreed that our group would 
  23. not have to follow the guidelines, because they were devised by an 
  24. inexperienced group that were not aware of the world outside of character 
  25. based Unix.  But, a couple of you inexperienced programmers have to pull a 
  26. hollier than thou routine.  I received many responses from users who agreed 
  27. that the standards were a joke.  Some of these were even posted publicly.  So 
  28. your me against the world philosophy is as ridiculous as agreeing with any of 
  29. those standards.  I'll go over more in detail now, why these standards are a 
  30. joke.
  31.  
  32. Agrivar
  33.  
  34. -------
  35.     -source files should have the extension .cc (not .cpp or .c).
  36.     I don't think I have to say anything here.
  37.  
  38.     -header files should have the extension .hh (not .hpp or .h).
  39.     I don't think I have to say anything here.
  40.     
  41.     -inline C++ functions should be in a file with the extension .icc (not 
  42. in the primary header).
  43.     I don't think I have to say anything here either.  But, I 
  44. will.  Although I've seen many people do this, it is contrary to normal 
  45. industry practices.  By using non-standard practices you increase the learning 
  46. necessary for new employees.  Bad.
  47.  
  48.     -do not use the /* */ comment, except when commenting out entire 
  49. sections of code.  
  50.     /* */ are the ANSI standard comment.  // are not.  When you have a 
  51. parameter not used warning, you should eliminate it using.
  52.     void f(int /* idControl */);
  53. You can't do this with //.  You could also delete the identifier, but then you 
  54. would lose context.
  55.  
  56.     -a class which can be instantiated with a "new" must have a copy 
  57. constructor, a destructor and an assignment operator definition.  
  58.     Most compilers (if not all) supply default copy construtors.  Unless 
  59. you think your class may have copy behavior problems, then writing copy 
  60. constructors is redundant.  When you have 100+ classes to write and where the 
  61. average copy constructor has 50 lines, you would need 100 hours to write the 
  62. additional robustness (or cumbersomeness).
  63.  
  64.     -never use #define instead or const.  
  65.     This is a good debate, but I still maintain that if your memory model 
  66. and compiler make #define data text and const code text, then you cannot 
  67. consider this a straight forward trade-off.
  68.  
  69.     -variable are to be declared with the smallest possible scope.
  70.     I'll leave this one alone.  I was only trying to enlargen the joke 
  71. with a funny example.  This served the purpose.  Generally this practice is 
  72. good.
  73.  
  74.     -don't use explicit type conversions.  
  75.     Anybody who has done heavy C++ programming knows how ridiculous this 
  76. rule is.  This is easy to implement in C, but impossible in the C++ Windows 
  77. environment.
  78.  
  79.     -don't use implicit type conversions implicitly, use them explicitly. 
  80.     See the previous rule.
  81.  
  82.     -every case statement must be terminated with a break statement.  
  83.     Why?  This is arbitrary and makes some programming algorithms harder 
  84. to implement.  Example: the messages handling switch statement.  You usually 
  85. break to fall to the default handling and return to skip the default handling.
  86.  
  87.     -don't use conditional compilation preprocessor directives.  
  88.     This is simply stupid.  The writers of the standard simply were not 
  89. aware of cross-platform development techniques.
  90.  
  91.     -optimize code only when you have a problem.  
  92.     Why not anticipate the problem?    
  93.  
  94.     -access functions are to be inline.  
  95.     This is the biggest fallacy in programming today.  If you make your 
  96. accessors inline, then you have defeated the purpose of data hiding.  If your 
  97. data's type changes, then you still have to recompile every object that 
  98. accesses the member.
  99.  
  100.     -give protected accessors for all data members.  
  101.     Proper encapsulation tells us otherwise.
  102.  
  103.     -++ and -- operations should be on a separate line.
  104.     This one is arbitrary.  I've heard people argue for this standard, but 
  105. their only reason is that they say it is less buggy and easily debugged.  I 
  106. just don't see why.
  107.  
  108.     -don't allocate memory and expected someone else will delete it later. 
  109.     Every project I've ever worked on had some feature that just blew this 
  110. standard into hell.
  111.  
  112. Agrivar
  113.